﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;
using System.Text;

namespace TestRabbitMQ
{
    public class RabbitMQConfig
    {

        /// <summary>
        /// 账号
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// 设置RabbitMQ服务端地址
        /// </summary>
        public string HostName { get; set; }

        public List<Assembly> Assemblys { get; private set; }

        /// <summary>
        /// 设置消息订阅者
        /// 1、将消费者执行方法集中定义
        /// 2、省去其他多余的反射
        /// </summary>
        /// <param name="assemblyNames">指定包含消息订阅者的程序集</param>
        public void SetAssemblyApplication(List<string> assemblyNames)
        {
            Assemblys = new List<Assembly>();
            assemblyNames.ForEach(item =>
            {
                var va = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(item));
                Assemblys.Add(va);
            });
        }
    }
}
